#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

//std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};

int main() {
	
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int n, k;
	std::cin >> n >> k;
	std::vector<int> a(n + 1);
	for(int i = 1; i <= n; i++) {
		std::cin >> a[i];
	}
	std::vector<int> temp;

	std::function<void(int)> dfs = [&](int x) -> void {
		if(x > n) {
			int sum = std::accumulate(all(temp), 0);
			if(sum % k == 0) {
				for(auto t : temp) {
					std::cout << t << " ";
				}
				std::cout << "\n";
			}
			return;
		}
		for(int i = 1; i <= a[x]; i++) {
			temp.push_back(i);
			dfs(x + 1);
			temp.pop_back();
		}
	};

	
	dfs(1);

	return 0;
}